package com.yk.faceapplication.adapter;

import java.util.List;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.allinpay.xed.R;


/**
 * @author fyales
 * @since 8/26/15.
 */
public class TagBaseAdapter extends BaseAdapter {

	private Context mContext;
	private List<String> mList;

	public TagBaseAdapter(Context context, List<String> list) {
		mContext = context;
		mList = list;
	}

	@Override
	public int getCount() {
		return mList.size();
	}

	@Override
	public String getItem(int position) {
		return mList.get(position);
	}

	@Override
	public long getItemId(int position) {
		return position;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		ViewHolder holder;
		if (convertView == null) {
			convertView = LayoutInflater.from(mContext).inflate(R.layout.tagview, null);
			holder = new ViewHolder();
			holder.tagBtn = (TextView) convertView.findViewById(R.id.tag_btn);
			convertView.setTag(holder);
		}
		else {
			holder = (ViewHolder) convertView.getTag();
		}
		if(position == 0){
			holder.tagBtn.setBackgroundResource(R.drawable.btn_stroke_zi);
			holder.tagBtn.setTextColor(mContext.getResources().getColor(R.color.zi));
		}else if(position == 1){
			holder.tagBtn.setBackgroundResource(R.drawable.btn_stroke_red);
			holder.tagBtn.setTextColor(mContext.getResources().getColor(R.color.red));
		}else if(position == 2){
			holder.tagBtn.setBackgroundResource(R.drawable.btn_stroke_339900);
			holder.tagBtn.setTextColor(mContext.getResources().getColor(R.color.color_339900));
		}else if(position == 3){
			holder.tagBtn.setBackgroundResource(R.drawable.btn_stroke_6666ff);
			holder.tagBtn.setTextColor(mContext.getResources().getColor(R.color.color_6666FF));
		}else if(position == 4){
			holder.tagBtn.setBackgroundResource(R.drawable.btn_stroke_ef9201);
			holder.tagBtn.setTextColor(mContext.getResources().getColor(R.color.color_EF9201));
		}else{
			holder.tagBtn.setBackgroundResource(R.drawable.btn_stroke_zi);
			holder.tagBtn.setTextColor(mContext.getResources().getColor(R.color.zi));
		}
		holder.tagBtn.setText(getItem(position));
//		final String text = getItem(position);
//		if (text.split("\\$").length > 1) {
//
//			switch (text.split("\\$")[1]) {
//			case "#FF0000":
//				holder.tagBtn.setBackgroundResource(R.drawable.btn_stroke_zi);
//				holder.tagBtn.setTextColor(mContext.getResources().getColor(R.color.zi));
//				break;
//			case "#9933CC":
//				holder.tagBtn.setBackgroundResource(R.drawable.btn_stroke_red);
//				holder.tagBtn.setTextColor(mContext.getResources().getColor(R.color.red));
//				break;
//			case "#339900":
//				holder.tagBtn.setBackgroundResource(R.drawable.btn_stroke_339900);
//				holder.tagBtn.setTextColor(mContext.getResources().getColor(R.color.color_339900));
//				break;
//			case "#6666FF":
//				holder.tagBtn.setBackgroundResource(R.drawable.btn_stroke_6666ff);
//				holder.tagBtn.setTextColor(mContext.getResources().getColor(R.color.color_6666FF));
//				break;
//			case "#EF9201":
//				holder.tagBtn.setBackgroundResource(R.drawable.btn_stroke_ef9201);
//				holder.tagBtn.setTextColor(mContext.getResources().getColor(R.color.color_EF9201));
//				break;
//			}
//		}
//		holder.tagBtn.setText(text.split("\\$")[0]);
		return convertView;
	}

	static class ViewHolder {
		TextView tagBtn;
	}
}